<?php
/**
 * Created by PhpStorm.
 * User: xuewl
 * Date: 2017/12/14
 * Time: 7:27
 */

namespace app\product\model;
use app\common\library\Model;

class QuestionTemplate extends Model
{
    protected $append = [
        'content_prop'
    ];

    protected $type = [
        'rules' => 'json',
    ];

    function getContentPropAttr($value, $data) {
        $props = json_decode($data['content'], true);
        $result = [];
        foreach($props as $prop_id => $prop) {
            $result[$prop_id]['name'] = \think\Db::name('form_prop')->where(['id' => $prop_id])->value('name');
            $result[$prop_id]['value'] = \think\Db::name('form_propvalue')->where(['id' => ['in', $prop]])->select();
        }
        return $result;
    }
}